<?php
	$TH_Month = array("","มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฏาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
	$start = 1;
?>
	<!--<div class="header">-->
	<div class="moduleHeader headerCalendar">
		<a title="ก่อนหน้า" href="javascript:void(0);" class="prev"></a>
		<span>&nbsp;&nbsp;กิจกรรมเดือน <?php echo $TH_Month[$dataModuleCalendarElement['m']];?> <?php echo $dataModuleCalendarElement['y'];?></span>
		<a title="ถัดไป" href="javascript:void(0);" class="next"></a> 
	</div>
	<div class="BodyCalendar">
		<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
			<thead>
				<tr>
					<th>SUN</th>
					<th>MON</th>
					<th>TUE</th>
					<th>WED</th>
					<th>THU</th>
					<th>FRI</th>
					<th>SAT</th>
				</tr>
			</thead>	
			<tbody>
				<?php for($i=0;$i<6;$i++):?>
				<?php if($start > $dataModuleCalendarElement['month_end']) continue;?>
				<tr>
					<?php for($j=0;$j<7;$j++):?>
						<?php if($i==0):?>
							<?php if($dataModuleCalendarElement['month_start'] <= $j):?>
								<td valign="top">
									<?php if(!empty($dataModuleCalendarActivity[$start][0])):?>
									<a href="javascript:void(0);" class="balloon">
										<div class="image">
											<?php echo exec_image(array(
												'folder' => 'calendar',
												'dimension' => ($j==0 || $j==6 ? '45':'40').'x40',
												'file_name' => @$dataModuleCalendarActivity[$start][0]['image']->calendar_file_name.'.'.@$dataModuleCalendarActivity[$start][0]['image']->calendar_file_ext,
												'alt' => ''.@$dataModuleCalendarActivity[$start][0]['calendar_subject'].'',	
												'title' => ''.@$dataModuleCalendarActivity[$start][0]['calendar_subject'].''	
											)
										);?>								
										</div>
									</a>
									<div style="display:none;">
										<ul>
											<?php foreach($dataModuleCalendarActivity[$start] as $value):?>
											<li><a href="<?php echo $news_url.'calendar/archives/'.$value['calendar_id'].'-'.seo_url($value['calendar_subject']);?>" target="_blank"><?php echo $value['calendar_subject'];?></a></li>
											<?php endforeach;?>
										</ul>
									</div>								
									<?php endif;?>
									<span <?php echo ($dataModuleCalendarElement['d']==$start ? 'class="current"':'');?>><?php echo $start;?></span>
								</td>
								<?php $start++;?>
							<?php else:?>
								<td>&nbsp;</td>
							<?php endif;?>
						<?php else:?>
							<?php if($start <= $dataModuleCalendarElement['month_end']):?>
								<td valign="top">
									<?php if(!empty($dataModuleCalendarActivity[$start][0])):?>
									<a href="javascript:void(0);" class="balloon">
										<div class="image">
											<?php echo exec_image(array(
												'folder' => 'calendar',
												'dimension' => ($j==0 || $j==6 ? '45':'40').'x40',
												'file_name' => @$dataModuleCalendarActivity[$start][0]['image']->calendar_file_name.'.'.@$dataModuleCalendarActivity[$start][0]['image']->calendar_file_ext,
												'alt' => ''.@$dataModuleCalendarActivity[$start][0]['calendar_subject'].'',	
												'title' => ''.@$dataModuleCalendarActivity[$start][0]['calendar_subject'].''	
											)
										);?>								
										</div>
									</a>
									<div style="display:none;">
										<ul>
											<?php foreach($dataModuleCalendarActivity[$start] as $value):?>
											<li><a href="<?php echo $news_url.'calendar/archives/'.$value['calendar_id'].'-'.seo_url($value['calendar_subject']);?>" target="_blank"><?php echo $value['calendar_subject'];?></a></li>
											<?php endforeach;?>
										</ul>
									</div>								
									<?php endif;?>						
									<span <?php echo ($dataModuleCalendarElement['d']==$start ? 'class="current"':'');?>><?php echo $start;?></span>
								</td>
								<?php $start++;?>
							<?php else:?>
								<td>&nbsp;</td>
							<?php endif;?>
						<?php endif;?>
					<?php endfor;?>
				</tr>
				<?php endfor;?>
			</tbody>
		</table>
	</div>
	<div class="FooterCalendar"></div>
	<a href="<?php echo $news_url.'calendar';?>" class="readMore" target="_blank">ดูกิจกรรมทั้งหมด &raquo;</a>
<script type="text/javascript" language="javascript">
(function($) {
/*whatever jQuery stuff*/
	$(function(){
		$('#module_news_calendar').find('.next').click(function(){
			$.ajax({
				type:'post',
				url:web_path+'module_calendar',
				data:({
					ajax:true,
					month:'<?php echo (($dataModuleCalendarElement["m"]+1) > 12 ? 1:($dataModuleCalendarElement["m"]+1));?>',
					year:'<?php echo (($dataModuleCalendarElement["m"]+1) > 12 ? ($dataModuleCalendarElement["y"]+1):$dataModuleCalendarElement["y"]);?>',
				})
			}).done(function(data){
				$('#module_news_calendar').html(data);
			});
		});
		$('#module_news_calendar').find('.prev').click(function(){
			$.ajax({
				type:'post',
				url:web_path+'module_calendar',
				data:({
					ajax:true,
					month:'<?php echo (($dataModuleCalendarElement["m"]-1) < 1 ? 12:($dataModuleCalendarElement["m"]-1));?>',
					year:'<?php echo (($dataModuleCalendarElement["m"]-1) < 1 ? ($dataModuleCalendarElement["y"]-1):$dataModuleCalendarElement["y"]);?>',
				})
			}).done(function(data){
				$('#module_news_calendar').html(data);
			});
		});	
		
		//Balloon ToolTips
		$(".balloon").each(function() { 
			$(".jquery_balloon").remove();
			$(this).balloon({ 
				contents: $(this).next().html(), 
				position: "top",
				classname: "jquery_balloon"
	  		});
  		});			
	});	
})(jQuery);
</script>	